/*Bubble Sort Algorithm*/
#include<stdio.h>
#include<string.h>
#include<time.h>
#define ARRAYSIZE 	400	
#define FALSE		0
#define TRUE 		1

void print_array(int a[])
{
	int i;
       	for(i=0;i<ARRAYSIZE;i++){
	       printf("- %d -", a[i]);
	}
	printf("\n");
}

int main() 
{
	int s[ARRAYSIZE];
	int i,j,t,steps=0,cont = TRUE;
	srand(time(0));
	for(i=0;i<ARRAYSIZE;i++){
		s[i] = random() % 1000;
	}
	print_array(s);
	printf("\n");
	for(j=0;cont&&j<ARRAYSIZE-1;j++){ 	//Here we don't go as far
		cont = FALSE;			//as the last element
		for(i=0;i<ARRAYSIZE-j-1;i++){	//
			steps++;
			if(s[i]>s[i+1]){	//Max value of expression
				t = s[i];	//is (n-2)>(n-1)
				s[i] = s[i+1];
				s[i+1] = t;
				cont = TRUE;
			}
		}
	}
	print_array(s);
	printf("Steps = %d\n",steps);
	return 1;	
}		
